package com.tledu.stu_manager.filter; /**
 *
 */

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "EncodingFilter", urlPatterns = "/*")
public class EncodingFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        String servletPath = req.getServletPath();
        //不过滤静态资源
        if (servletPath.startsWith("/resources")) {
            chain.doFilter(req, res);
            return;
        }
        req.setCharacterEncoding("utf-8");
        res.setCharacterEncoding("utf-8");
        chain.doFilter(req, res);
    }
}
